package com.haofengsoft.scce;

import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;

import com.haofengsoft.scce.common.client.VolleyBean;
import com.haofengsoft.scce.common.client.VolleyInterface;
import com.haofengsoft.scce.common.client.VolleyManage;
import com.haofengsoft.scce.common.config.ConstantConfig;
import com.haofengsoft.scce.controller.AdvertController;

public class WelcomeActivity extends Activity {
	/**
	 * Called when the activity is first created.
	 */

	private Timer timer;
	TimerTask task = new TimerTask() {
		@Override
		public void run() {
			timer.cancel();
			Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
			startActivity(intent);
			finish();
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		timer = new Timer();
		timer.schedule(task, 2000);
		initAdvertData();
	}

	private void initAdvertData() {
		Map<String, Object> mapParam = new HashMap<String, Object>();
		VolleyManage.getInstance().methodPost(WelcomeActivity.this, null, ConstantConfig.ADVERTS_URL, mapParam,
				new AdvertVolleyReal());
	}

	class AdvertVolleyReal implements VolleyInterface {

		@Override
		public void gainData(VolleyBean bean) {
			if (bean.isSuccess()) {
				AdvertController.getInstance(WelcomeActivity.this).gainBuyInfoModels(bean.getContent());

			}
		}
	}
}
